package unionfind;

public class UnionFind implements UF{

    private int size;
    private int []data;

    public UnionFind(int size){
        this.size = size;

        data = new int[size];
        for(int i=0;i<size;i++){
            data[i] = i;
        }
    }

    public int getSize(){
        return size;
    }

    @Override
    public boolean isConnected(int p, int q) {

        return data[p] == data[q];
    }

    @Override
    public void union(int p, int q) {
        int pValue = data[p];
        int qValue = data[q];
        for(int i=0;i<size;i++){
            if(data[i] == pValue){
                data[i] = qValue;
            }
        }
    }


}
